package cn.sptpc.Controller;

import cn.sptpc.service.DepartmentService;
import cn.sptpc.service.impl.DepartmentServiceI;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/department.do")
public class DepartmentServlet extends HttpServlet {
    private DepartmentService service = new DepartmentServiceI();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json;charset=gbk");
        String tran = request.getParameter("tran");
        if ("select".equals(tran)){
            String type = request.getParameter("type");
            if("self".equals(type)){
                String gDepartments = service.getAllDepartment(request);
                response.getWriter().write(gDepartments);
            }else if("all".equals(type)){
                String gDepartments = service.getAllDepartment();
                response.getWriter().write(gDepartments);
            }
        }else if("add".equals(tran)){
            response.getWriter().write(service.insertDepartment(request));
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
